# -*- coding: utf8 -*-
import numpy as np
import polygon_contains_point as pinp


def range_float(start,end,step):
    """
    生成间隔相等的实数序列
    :param start: float
    :param end: float
    :param step: float
    :return: generator
    """
    start = np.float64(start)
    end = np.float64(end)
    if start > end:
        raise Exception('error')
    if start == end:
        yield start
    else:
        mid = start
        while mid < end:
            yield mid
            mid = np.round(mid + step,decimals=10)
        else:
            yield end


def generate_points(longitude_list,latitude_list):
    """
    根据经纬度生成网格点
    :param longitude_list: list
    :param latitude_list: list
    :return:
    """
    xv, yv = np.meshgrid(longitude_list, latitude_list)
    for i in range(len(latitude_list)):
        for j in range(len(longitude_list)):
            yield xv[i, j], yv[i, j]


def judge_point_in_polygon(point,longitude_polygon,latitude_polygon):
    long,lat = point
    vertex = len(longitude_polygon)
    result = pinp.point_in_polygon(vertex, longitude_polygon, latitude_polygon, long,lat)
    return result










